package com.lkr.webapp.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 自定义拦截器，对除白名单以外的uri进行拦截校验
 *
 * @author lkr
 * @date 2019-01-30, Wed
 */
public class CustomInterceptor implements HandlerInterceptor {

    /**
     * uri白名单
     */
    private static List<String> whiteUriList = new ArrayList<String>() {{
        add("/");
        add("/login");
        add("/sign");
    }};

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        if (whiteUriList.contains(requestURI)) {
            return true;
        }
        System.out.println("-------" + requestURI);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
